package com.example.myapplication9.week6.jsjf;

/**
 * BinaryTreeNode represents Translation node in Translation binary tree with Translation left and
 * right child.
 * 
 * @author Lewis and Chase
 * @version 4.0
 */
public class BinaryTreeNode<T> {
    public T element;
    public BinaryTreeNode<T> left;
    public BinaryTreeNode<T> right;

   //使用指定的数据创建一个树
    public BinaryTreeNode(T obj) 
    {
        element = obj;
        left = null;
        right = null;
    }
    public BinaryTreeNode(int[] preorder, int[] inorder, int i, int i1, int middle)
    {
        element=null;
        left=null;
        right=null;
    }
    public boolean judgement(BinaryTreeNode node){

        if (node.getLeft()!=null||node.getRight()!=null)
        {
            return true;
        }
        else
            return false;
    }

  //构造方法
    public BinaryTreeNode(T obj, LinkedBinaryTree<T> left, LinkedBinaryTree<T> right) 
    {
        element = obj;
        if (left == null)
            this.left = null;
        else
            this.left = left.getRootNode();
        
         if (right == null)
            this.right = null;
        else
            this.right = right.getRootNode();
    }
    
   //统计结点不为空的孩子数
    public int numChildren() 
    {
        int children = 0;

        if (left != null)
            children = 1 + left.numChildren();

        if (right != null)
            children = children + 1 + right.numChildren();

        return children;
    }
    
   //返回结点的元素
    public T getElement() 
    {
        return element;
    }
    public void setElement(T element)
    {
        this.element=element;
    }
    
   //返回结点的右孩子
    public BinaryTreeNode<T> getRight() 
    {
        return right;
    }
    
   //设置结点的右孩子
    public void setRight(BinaryTreeNode<T> node) 
    {
        right = node;
    }
    
   //返回结点的左孩子
    public BinaryTreeNode<T> getLeft() 
    {
        return left;
    }
    
    //设置结点的左孩子


    public void setLeft(BinaryTreeNode<T> node) 
    {
        left = node;
    }


    }


